package com.topisv.tms.web.work;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.topisv.tms.entity.EdiOrder;
import com.topisv.tms.entity.work.WorkOrder;
import com.topisv.tms.service.EdiOrderService;
import com.topisv.tms.service.vo.PrinterModel;
import com.topisv.tms.service.work.WorkOrderService;
import com.topisv.tms.utils.print.PickPrintUtil;
import com.topisv.tms.web.base.BaseController;

/**
 * 打印电子面单
 *  Date          Author       Version       Description
 * ----------------------------------------------------------
 *  2014-9-1      CC            1.0           Create
 */
@Controller
@RequestMapping({ "/printMailExpress" })
public class PrintMailExpressController extends BaseController {
	
	@Autowired
	private EdiOrderService ediOrderService;
	@Autowired
	private WorkOrderService workOrderService;
	@Autowired
	private PickPrintUtil pickPrintUtil;
	
	@RequestMapping(value = "showExpressTemplate")
	public String showExpressTemplate(Model model,HttpServletResponse response,
			@RequestParam(value = "ordeno", required = false) String ordeno, 
			@RequestParam(value = "taskCode", required = false) String taskCode, 
			@RequestParam(value = "cpCode", required = false, defaultValue = "YTO") String cpCode
			){
		try{
			EdiOrder order = ediOrderService.findByOrdeno(ordeno);
			WorkOrder workOrder = workOrderService.loadOrder(order.getBatchTaskCode(), order.getOrdeno());
			PrinterModel printerModel = new PrinterModel();
			pickPrintUtil.getExpressStyleModel(printerModel,order);
			model.addAttribute("printerModel", printerModel);
		}catch(Exception e){
			log.error("showExpressTemplate case some error",e);
		}
		return "expressPrinting/mailExpress_" + cpCode;
	}

}
